﻿#ifndef ANPR_CAMERA_H
#define ANPR_CAMERA_H

#include <log4cxx/logger.h>
#include "opencv2/core/core.hpp"
#include "opencv2/core/core_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "CameraBase.h"
#include "FFmpegCamera.h"
#ifndef __aarch64__
#include "HikCamera.h"
#endif
#ifdef _WIN32
#include "ICECamera.h"
#endif
#include "ANPRTH.h"

#define MAX_CAMERA_NUM 2
#define GBK_TO_UTF8 1

typedef void(*ANPRCameraCallback)(int port, const char *lpNumber, const char* imagePath, void *context);

class ANPRCamera
{
public:
    ANPRCamera();
    ~ANPRCamera();
    void Init(int index, HWND windowId);
    int Connect(int index);
    int Disconnect(int index);
    int StartSaveVideo(int index, const char *videoPath);
    int StopSaveVideo(int index);
    static void VideoDataCallback(int handle, unsigned char *buffer, int size, int width, int height, int type, void *context);
    static void ANPRInfoCallback(int handle, const char *lpNumber, unsigned char* buffer, int size, int width, int height, void *context);

    ANPRCameraCallback callback = 0;
    void *context = 0;
    CameraBase *camera[MAX_CAMERA_NUM];
    int handle[MAX_CAMERA_NUM];
    IplImage *image[MAX_CAMERA_NUM];
    std::string lpNumber[MAX_CAMERA_NUM];
    std::string imagePath[MAX_CAMERA_NUM];
    ANPRTH *anpr;
    std::string configFilePath;
    int captureImage; // -1： 不抓图, 其他: 对应编号的车牌相机抓图
    int ANPRMode; // 0: 图像模式, 1: 视频模式, 2: 设备识别
    int minPlateWidth;
    int maxPlateWidth;
    int maxImageWidth;
    int maxImageHeight;
    bool enableRegion;
    RECT region;
    std::string province;
    bool enableDoubleRowYellowLP;
    bool enableDoubleRowPoliceLP;
    bool enableDoubleRowArmyLP;
    bool enableEmbassyLP;
    bool enableTractorLP;
    bool enableAirportLP;
    bool enableOutputPath = false;
    std::string outputPath;
    log4cxx::LoggerPtr logger;
    int charset_conv = 0;

private:
    void LoadConfigParams();
#ifdef _WIN32
    std::string UTF8ToGBK(const std::string& str);
#endif
#ifdef __linux__
    int GBKToUTF8(char* src, size_t* srclen, char* dest, size_t* destlen);
#endif
};

#endif
